package com.gugee.ins.web.service;


import com.gugee.ins.web.model.mysql.InsDicCategory;
import com.gugee.ins.web.model.mysql.InsDicGeneration;
import com.gugee.ins.web.model.mysql.InsDicLanguage;
import com.gugee.ins.web.model.mysql.InsDicNation;
import com.gugee.ins.web.repository.InsDicCategoryRepository;
import com.gugee.ins.web.repository.InsDicGenerationRepository;
import com.gugee.ins.web.repository.InsDicLanguageRepository;
import com.gugee.ins.web.repository.InsDicNationRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class DicService {

    @Autowired
    InsDicGenerationRepository insDicGenerationRepository;

    @Autowired
    InsDicLanguageRepository insDicLanguageRepository;

    @Autowired
    InsDicNationRepository insDicNationRepository;

    @Autowired
    InsDicCategoryRepository insDicCategoryRepository;

    public List<InsDicGeneration> getDicGenerationByType(int type){
        return insDicGenerationRepository.findByGenerationTypeOrderById(type);
    }

    public List<InsDicNation> getNations(Integer type){
        if(null != type){
            return insDicNationRepository.findByTypeOrderByName(type);
        }
        return insDicNationRepository.findAllByOrderByName();
    }

    public List<InsDicLanguage> getLanguage(Integer type){
        if(null != type){
            return insDicLanguageRepository.findByTypeOrderByName(type);
        }
        return insDicLanguageRepository.findAllByOrderByName();
    }

    public List<InsDicCategory> getOverallCategory(){
        return insDicCategoryRepository.findOverall();
    }

    public List<InsDicCategory> getCategoryByOverallCategory(String overall){
        return insDicCategoryRepository.findByOverallCategory(overall);
    }

    public String getCode(String nationName){
        return insDicNationRepository.findCodeByName(nationName);
    }


}
